package com.tjetc.controller;

import com.github.pagehelper.PageInfo;
import com.tjetc.domain.HDepartment;
import com.tjetc.service.HDepartmentService;
import com.tjetc.service.impl.HDepartmentServiceImpl;
import com.tjetc.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (h_department)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/h_department")
public class HDepartmentController {
    /**
     * 服务对象
     */
    @Resource
    private HDepartmentService hDepartmentService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public HDepartment selectOne(Integer id) {
        return hDepartmentService.selectByPrimaryKey(id);
    }

    @GetMapping("selAll")
    public PageInfo<HDepartment> selAll(
            @RequestParam(value = "name", defaultValue = "") String name,
            @RequestParam(value = "curPage", defaultValue = "1") Integer curPage,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
            @RequestParam(value = "hid",required = false) Integer hid
    ) {
        return hDepartmentService.selAll(name, curPage, pageSize,hid);
    }

    @GetMapping("delById")
    public Integer delById(@RequestParam("id") Integer id) {
        return hDepartmentService.delById(id);
    }

    @GetMapping("update")
    public Integer update(
            @RequestParam("id") Integer id, @RequestParam("name") String name, @RequestParam("hid") Integer hid, @RequestParam("ispoint") Integer ispoint) {
        HDepartment hDepartment = new HDepartment();
        hDepartment.setId(id);
        hDepartment.setName(name);
        hDepartment.setHid(hid);
        hDepartment.setIspoint(ispoint);
        return hDepartmentService.update(hDepartment);
    }

    @GetMapping("add")
    public Integer add(@RequestParam("name") String name, @RequestParam("hid") Integer hid, @RequestParam("ispoint") Integer ispoint) {
        HDepartment hDepartment = new HDepartment();
        hDepartment.setName(name);
        hDepartment.setHid(hid);
        hDepartment.setIspoint(ispoint);
        return hDepartmentService.add(hDepartment);
    }

    @GetMapping("selectByHid")
    public Result selectByHid(@RequestParam("hid") Integer hid) {
        return hDepartmentService.selectByHid(hid);
    }
}
